<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: selector   selector-css2.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css" />
	<link rel="stylesheet" type="text/css" href="assets/api.css" />

    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="Yahoo! UI Library">Yahoo! UI Library</a></h1>
        <h3>Selector Utility&nbsp; <span class="subtitle">2.9.0</span></h3>
        <a href="./index.html" title="Yahoo! UI Library">Yahoo! UI Library</a> 
            &gt; <a href="./module_selector.html" title="selector">selector</a>
                
                 &gt; selector-css2.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
                        <div class="highlight"><pre><span class="cm">/**</span>
<span class="cm"> * The selector module provides helper methods allowing CSS2 Selectors to be used with DOM elements.</span>
<span class="cm"> * @module dom</span>
<span class="cm"> * @submodule selector-css2</span>
<span class="cm"> * @for Selector</span>
<span class="cm"> */</span>

<span class="cm">/**</span>
<span class="cm"> * Provides helper methods for collecting and filtering DOM elements.</span>
<span class="cm"> */</span>

<span class="kd">var</span> <span class="nx">PARENT_NODE</span> <span class="o">=</span> <span class="s1">&#39;parentNode&#39;</span><span class="p">,</span>
    <span class="nx">TAG_NAME</span> <span class="o">=</span> <span class="s1">&#39;tagName&#39;</span><span class="p">,</span>
    <span class="nx">ATTRIBUTES</span> <span class="o">=</span> <span class="s1">&#39;attributes&#39;</span><span class="p">,</span>
    <span class="nx">COMBINATOR</span> <span class="o">=</span> <span class="s1">&#39;combinator&#39;</span><span class="p">,</span>
    <span class="nx">PSEUDOS</span> <span class="o">=</span> <span class="s1">&#39;pseudos&#39;</span><span class="p">,</span>

    <span class="nx">SelectorCSS2</span> <span class="o">=</span> <span class="p">{</span>
        <span class="nx">_reRegExpTokens</span><span class="o">:</span> <span class="sr">/([\^\$\?\[\]\*\+\-\.\(\)\|\\])/</span><span class="p">,</span> <span class="c1">// TODO: move?</span>
        <span class="nx">SORT_RESULTS</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
        <span class="nx">_children</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">tag</span><span class="p">)</span> <span class="p">{</span>
            <span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">children</span><span class="p">,</span>
                <span class="nx">i</span><span class="p">,</span>
                <span class="nx">children</span> <span class="o">=</span> <span class="p">[],</span>
                <span class="nx">childNodes</span><span class="p">,</span>
                <span class="nx">child</span><span class="p">;</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">children</span> <span class="o">&amp;&amp;</span> <span class="nx">tag</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span><span class="p">.</span><span class="nx">children</span><span class="p">.</span><span class="nx">tags</span><span class="p">)</span> <span class="p">{</span>
                <span class="nx">children</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">children</span><span class="p">.</span><span class="nx">tags</span><span class="p">(</span><span class="nx">tag</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">((</span><span class="o">!</span><span class="nx">ret</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span><span class="p">[</span><span class="nx">TAG_NAME</span><span class="p">])</span> <span class="o">||</span> <span class="p">(</span><span class="nx">ret</span> <span class="o">&amp;&amp;</span> <span class="nx">tag</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// only HTMLElements have children</span>
                <span class="nx">childNodes</span> <span class="o">=</span> <span class="nx">ret</span> <span class="o">||</span> <span class="nx">node</span><span class="p">.</span><span class="nx">childNodes</span><span class="p">;</span>
                <span class="nx">ret</span> <span class="o">=</span> <span class="p">[];</span>
                <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="p">(</span><span class="nx">child</span> <span class="o">=</span> <span class="nx">childNodes</span><span class="p">[</span><span class="nx">i</span><span class="o">++</span><span class="p">]);)</span> <span class="p">{</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">child</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span>
                        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">tag</span> <span class="o">||</span> <span class="nx">tag</span> <span class="o">===</span> <span class="nx">child</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">ret</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">child</span><span class="p">);</span>
                        <span class="p">}</span>
                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="k">return</span> <span class="nx">ret</span> <span class="o">||</span> <span class="p">[];</span>
        <span class="p">},</span>

        <span class="nx">_re</span><span class="o">:</span> <span class="p">{</span>
            <span class="c1">//attr: /(\[.*\])/g,</span>
            <span class="nx">attr</span><span class="o">:</span> <span class="sr">/(\[[^\]]*\])/g</span><span class="p">,</span>
            <span class="c1">//esc: /\\[:\[][\w\d\]]*/gi,</span>
            <span class="nx">esc</span><span class="o">:</span> <span class="sr">/\\[:\[\]\(\)#\.\&#39;\&gt;+~&quot;]/gi</span><span class="p">,</span>
            <span class="c1">//pseudos: /:([\-\w]+(?:\(?:[&#39;&quot;]?(.+)[&#39;&quot;]?\))*)/i</span>
            <span class="nx">pseudos</span><span class="o">:</span> <span class="sr">/(\([^\)]*\))/g</span>
        <span class="p">},</span>

        <span class="cm">/**</span>
<span class="cm">         * Mapping of shorthand tokens to corresponding attribute selector </span>
<span class="cm">         * @property shorthand</span>
<span class="cm">         * @type object</span>
<span class="cm">         */</span>
        <span class="nx">shorthand</span><span class="o">:</span> <span class="p">{</span>
            <span class="c1">//&#39;\\#([^\\s\\\\(\\[:]*)&#39;: &#39;[id=$1]&#39;,</span>
            <span class="s1">&#39;\\#(-?[_a-z]+[-\\w\\uE000]*)&#39;</span><span class="o">:</span> <span class="s1">&#39;[id=$1]&#39;</span><span class="p">,</span>
            <span class="c1">//&#39;\\#([^\\s\\\.:\\[\\]]*)&#39;: &#39;[id=$1]&#39;,</span>
            <span class="c1">//&#39;\\.([^\\s\\\\(\\[:]*)&#39;: &#39;[className=$1]&#39;</span>
            <span class="s1">&#39;\\.(-?[_a-z]+[-\\w\\uE000]*)&#39;</span><span class="o">:</span> <span class="s1">&#39;[className~=$1]&#39;</span>
        <span class="p">},</span>

        <span class="cm">/**</span>
<span class="cm">         * List of operators and corresponding boolean functions. </span>
<span class="cm">         * These functions are passed the attribute and the current node&#39;s value of the attribute.</span>
<span class="cm">         * @property operators</span>
<span class="cm">         * @type object</span>
<span class="cm">         */</span>
        <span class="nx">operators</span><span class="o">:</span> <span class="p">{</span>
            <span class="s1">&#39;&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">attr</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="o">!!</span><span class="nx">node</span><span class="p">.</span><span class="nx">getAttribute</span><span class="p">(</span><span class="nx">attr</span><span class="p">);</span> <span class="p">},</span> <span class="c1">// Just test for existence of attribute</span>
            <span class="c1">//&#39;&#39;: &#39;.+&#39;,</span>
            <span class="c1">//&#39;=&#39;: &#39;^{val}$&#39;, // equality</span>
            <span class="s1">&#39;~=&#39;</span><span class="o">:</span> <span class="s1">&#39;(?:^|\\s+){val}(?:\\s+|$)&#39;</span><span class="p">,</span> <span class="c1">// space-delimited</span>
            <span class="s1">&#39;|=&#39;</span><span class="o">:</span> <span class="s1">&#39;^{val}(?:-|$)&#39;</span> <span class="c1">// optional hyphen-delimited</span>
        <span class="p">},</span>

        <span class="nx">pseudos</span><span class="o">:</span> <span class="p">{</span>
           <span class="s1">&#39;first-child&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span> 
                <span class="k">return</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_children</span><span class="p">(</span><span class="nx">node</span><span class="p">[</span><span class="nx">PARENT_NODE</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> <span class="o">===</span> <span class="nx">node</span><span class="p">;</span> 
            <span class="p">}</span> 
        <span class="p">},</span>

        <span class="nx">_bruteQuery</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">selector</span><span class="p">,</span> <span class="nx">root</span><span class="p">,</span> <span class="nx">firstOnly</span><span class="p">)</span> <span class="p">{</span>
            <span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="p">[],</span>
                <span class="nx">nodes</span> <span class="o">=</span> <span class="p">[],</span>
                <span class="nx">tokens</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_tokenize</span><span class="p">(</span><span class="nx">selector</span><span class="p">),</span>
                <span class="nx">token</span> <span class="o">=</span> <span class="nx">tokens</span><span class="p">[</span><span class="nx">tokens</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">],</span>
                <span class="nx">rootDoc</span> <span class="o">=</span> <span class="nx">Y_getDoc</span><span class="p">(</span><span class="nx">root</span><span class="p">),</span>
                <span class="nx">child</span><span class="p">,</span>
                <span class="nx">id</span><span class="p">,</span>
                <span class="nx">className</span><span class="p">,</span>
                <span class="nx">tagName</span><span class="p">;</span>


            <span class="c1">// if we have an initial ID, set to root when in document</span>
            <span class="cm">/*</span>
<span class="cm">            if (tokens[0] &amp;&amp; rootDoc === root &amp;&amp;  </span>
<span class="cm">                    (id = tokens[0].id) &amp;&amp;</span>
<span class="cm">                    rootDoc.getElementById(id)) {</span>
<span class="cm">                root = rootDoc.getElementById(id);</span>
<span class="cm">            }</span>
<span class="cm">            */</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
                <span class="c1">// prefilter nodes</span>
                <span class="nx">id</span> <span class="o">=</span> <span class="nx">token</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
                <span class="nx">className</span> <span class="o">=</span> <span class="nx">token</span><span class="p">.</span><span class="nx">className</span><span class="p">;</span>
                <span class="nx">tagName</span> <span class="o">=</span> <span class="nx">token</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">||</span> <span class="s1">&#39;*&#39;</span><span class="p">;</span>

                <span class="k">if</span> <span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// non-IE lacks DOM api on doc frags</span>
                    <span class="c1">// try ID first, unless no root.all &amp;&amp; root not in document</span>
                    <span class="c1">// (root.all works off document, but not getElementById)</span>
                    <span class="c1">// TODO: move to allById?</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">id</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">all</span> <span class="o">||</span> <span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">nodeType</span> <span class="o">===</span> <span class="mi">9</span> <span class="o">||</span> <span class="nx">Y_DOM_inDoc</span><span class="p">(</span><span class="nx">root</span><span class="p">))))</span> <span class="p">{</span>
                        <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">Y_DOM_allById</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">root</span><span class="p">);</span>
                    <span class="c1">// try className</span>
                    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">className</span><span class="p">)</span> <span class="p">{</span>
                        <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">root</span><span class="p">.</span><span class="nx">getElementsByClassName</span><span class="p">(</span><span class="nx">className</span><span class="p">);</span>
                    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// default to tagName</span>
                        <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">root</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="nx">tagName</span><span class="p">);</span>
                    <span class="p">}</span>

                <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// brute getElementsByTagName(&#39;*&#39;)</span>
                    <span class="nx">child</span> <span class="o">=</span> <span class="nx">root</span><span class="p">.</span><span class="nx">firstChild</span><span class="p">;</span>
                    <span class="k">while</span> <span class="p">(</span><span class="nx">child</span><span class="p">)</span> <span class="p">{</span>
                        <span class="k">if</span> <span class="p">(</span><span class="nx">child</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// only collect HTMLElements</span>
                            <span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">child</span><span class="p">);</span>
                        <span class="p">}</span>
                        <span class="nx">child</span> <span class="o">=</span> <span class="nx">child</span><span class="p">.</span><span class="nx">nextSilbing</span> <span class="o">||</span> <span class="nx">child</span><span class="p">.</span><span class="nx">firstChild</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="p">}</span>
                <span class="k">if</span> <span class="p">(</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
                    <span class="nx">ret</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_filterNodes</span><span class="p">(</span><span class="nx">nodes</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">,</span> <span class="nx">firstOnly</span><span class="p">);</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="k">return</span> <span class="nx">ret</span><span class="p">;</span>
        <span class="p">},</span>
        
        <span class="nx">_filterNodes</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">nodes</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">,</span> <span class="nx">firstOnly</span><span class="p">)</span> <span class="p">{</span>
            <span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
                <span class="nx">j</span><span class="p">,</span>
                <span class="nx">len</span> <span class="o">=</span> <span class="nx">tokens</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span>
                <span class="nx">n</span> <span class="o">=</span> <span class="nx">len</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
                <span class="nx">result</span> <span class="o">=</span> <span class="p">[],</span>
                <span class="nx">node</span> <span class="o">=</span> <span class="nx">nodes</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">node</span><span class="p">,</span>
                <span class="nx">getters</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">getters</span><span class="p">,</span>
                <span class="nx">operator</span><span class="p">,</span>
                <span class="nx">combinator</span><span class="p">,</span>
                <span class="nx">token</span><span class="p">,</span>
                <span class="nx">path</span><span class="p">,</span>
                <span class="nx">pass</span><span class="p">,</span>
                <span class="c1">//FUNCTION = &#39;function&#39;,</span>
                <span class="nx">value</span><span class="p">,</span>
                <span class="nx">tests</span><span class="p">,</span>
                <span class="nx">test</span><span class="p">;</span>

            <span class="c1">//do {</span>
            <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="p">(</span><span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">nodes</span><span class="p">[</span><span class="nx">i</span><span class="o">++</span><span class="p">]);)</span> <span class="p">{</span>
                <span class="nx">n</span> <span class="o">=</span> <span class="nx">len</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
                <span class="nx">path</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
                
                <span class="nx">testLoop</span><span class="o">:</span>
                <span class="k">while</span> <span class="p">(</span><span class="nx">tmpNode</span> <span class="o">&amp;&amp;</span> <span class="nx">tmpNode</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span>
                    <span class="nx">token</span> <span class="o">=</span> <span class="nx">tokens</span><span class="p">[</span><span class="nx">n</span><span class="p">];</span>
                    <span class="nx">tests</span> <span class="o">=</span> <span class="nx">token</span><span class="p">.</span><span class="nx">tests</span><span class="p">;</span>
                    <span class="nx">j</span> <span class="o">=</span> <span class="nx">tests</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">j</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">pass</span><span class="p">)</span> <span class="p">{</span>
                        <span class="k">while</span> <span class="p">((</span><span class="nx">test</span> <span class="o">=</span> <span class="nx">tests</span><span class="p">[</span><span class="o">--</span><span class="nx">j</span><span class="p">]))</span> <span class="p">{</span>
                            <span class="nx">operator</span> <span class="o">=</span> <span class="nx">test</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
                            <span class="k">if</span> <span class="p">(</span><span class="nx">getters</span><span class="p">[</span><span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span> <span class="p">{</span>
                                <span class="nx">value</span> <span class="o">=</span> <span class="nx">getters</span><span class="p">[</span><span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">]](</span><span class="nx">tmpNode</span><span class="p">,</span> <span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
                            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                                <span class="nx">value</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">[</span><span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">]];</span>
                                <span class="c1">// use getAttribute for non-standard attributes</span>
                                <span class="k">if</span> <span class="p">(</span><span class="nx">value</span> <span class="o">===</span> <span class="kc">undefined</span> <span class="o">&amp;&amp;</span> <span class="nx">tmpNode</span><span class="p">.</span><span class="nx">getAttribute</span><span class="p">)</span> <span class="p">{</span>
                                    <span class="nx">value</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">.</span><span class="nx">getAttribute</span><span class="p">(</span><span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
                                <span class="p">}</span>
                            <span class="p">}</span>

                            <span class="k">if</span> <span class="p">((</span><span class="nx">operator</span> <span class="o">===</span> <span class="s1">&#39;=&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">value</span> <span class="o">!==</span> <span class="nx">test</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">||</span>  <span class="c1">// fast path for equality</span>
                                <span class="p">(</span><span class="k">typeof</span> <span class="nx">operator</span> <span class="o">!==</span> <span class="s1">&#39;string&#39;</span> <span class="o">&amp;&amp;</span> <span class="c1">// protect against String.test monkey-patch (Moo)</span>
                                <span class="nx">operator</span><span class="p">.</span><span class="nx">test</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">operator</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="o">||</span>  <span class="c1">// regex test</span>
                                <span class="p">(</span><span class="o">!</span><span class="nx">operator</span><span class="p">.</span><span class="nx">test</span> <span class="o">&amp;&amp;</span> <span class="c1">// protect against RegExp as function (webkit)</span>
                                        <span class="k">typeof</span> <span class="nx">operator</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">operator</span><span class="p">(</span><span class="nx">tmpNode</span><span class="p">,</span> <span class="nx">test</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">test</span><span class="p">[</span><span class="mi">2</span><span class="p">])))</span> <span class="p">{</span> <span class="c1">// function test</span>

                                <span class="c1">// skip non element nodes or non-matching tags</span>
                                <span class="k">if</span> <span class="p">((</span><span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">[</span><span class="nx">path</span><span class="p">]))</span> <span class="p">{</span>
                                    <span class="k">while</span> <span class="p">(</span><span class="nx">tmpNode</span> <span class="o">&amp;&amp;</span>
                                        <span class="p">(</span><span class="o">!</span><span class="nx">tmpNode</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">||</span>
                                            <span class="p">(</span><span class="nx">token</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">&amp;&amp;</span> <span class="nx">token</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">!==</span> <span class="nx">tmpNode</span><span class="p">.</span><span class="nx">tagName</span><span class="p">))</span>
                                    <span class="p">)</span> <span class="p">{</span>
                                        <span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">[</span><span class="nx">path</span><span class="p">];</span> 
                                    <span class="p">}</span>
                                <span class="p">}</span>
                                <span class="k">continue</span> <span class="nx">testLoop</span><span class="p">;</span>
                            <span class="p">}</span>
                        <span class="p">}</span>
                    <span class="p">}</span>

                    <span class="nx">n</span><span class="o">--</span><span class="p">;</span> <span class="c1">// move to next token</span>
                    <span class="c1">// now that we&#39;ve passed the test, move up the tree by combinator</span>
                    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">pass</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nx">combinator</span> <span class="o">=</span> <span class="nx">token</span><span class="p">.</span><span class="nx">combinator</span><span class="p">))</span> <span class="p">{</span>
                        <span class="nx">path</span> <span class="o">=</span> <span class="nx">combinator</span><span class="p">.</span><span class="nx">axis</span><span class="p">;</span>
                        <span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">[</span><span class="nx">path</span><span class="p">];</span>

                        <span class="c1">// skip non element nodes</span>
                        <span class="k">while</span> <span class="p">(</span><span class="nx">tmpNode</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">tmpNode</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">tmpNode</span> <span class="o">=</span> <span class="nx">tmpNode</span><span class="p">[</span><span class="nx">path</span><span class="p">];</span> 
                        <span class="p">}</span>

                        <span class="k">if</span> <span class="p">(</span><span class="nx">combinator</span><span class="p">.</span><span class="nx">direct</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// one pass only</span>
                            <span class="nx">path</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span> 
                        <span class="p">}</span>

                    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// success if we made it this far</span>
                        <span class="nx">result</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
                        <span class="k">if</span> <span class="p">(</span><span class="nx">firstOnly</span><span class="p">)</span> <span class="p">{</span>
                            <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
                        <span class="p">}</span>
                        <span class="k">break</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">}</span><span class="c1">// while (tmpNode = node = nodes[++i]);</span>
            <span class="nx">node</span> <span class="o">=</span> <span class="nx">tmpNode</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
            <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
        <span class="p">},</span>

        <span class="nx">combinators</span><span class="o">:</span> <span class="p">{</span>
            <span class="s1">&#39; &#39;</span><span class="o">:</span> <span class="p">{</span>
                <span class="nx">axis</span><span class="o">:</span> <span class="s1">&#39;parentNode&#39;</span>
            <span class="p">},</span>

            <span class="s1">&#39;&gt;&#39;</span><span class="o">:</span> <span class="p">{</span>
                <span class="nx">axis</span><span class="o">:</span> <span class="s1">&#39;parentNode&#39;</span><span class="p">,</span>
                <span class="nx">direct</span><span class="o">:</span> <span class="kc">true</span>
            <span class="p">},</span>


            <span class="s1">&#39;+&#39;</span><span class="o">:</span> <span class="p">{</span>
                <span class="nx">axis</span><span class="o">:</span> <span class="s1">&#39;previousSibling&#39;</span><span class="p">,</span>
                <span class="nx">direct</span><span class="o">:</span> <span class="kc">true</span>
            <span class="p">}</span>
        <span class="p">},</span>

        <span class="nx">_parsers</span><span class="o">:</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">ATTRIBUTES</span><span class="p">,</span>
                <span class="c1">//re: /^\[(-?[a-z]+[\w\-]*)+([~\|\^\$\*!=]=?)?[&#39;&quot;]?([^\]]*?)[&#39;&quot;]?\]/i,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^\uE003(-?[a-z]+[\w\-]*)+([~\|\^\$\*!=]=?)?[&#39;&quot;]?([^\uE004&#39;&quot;]*)[&#39;&quot;]?\uE004/i</span><span class="p">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">match</span><span class="p">,</span> <span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
                    <span class="kd">var</span> <span class="nx">operator</span> <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">||</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
                        <span class="nx">operators</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">operators</span><span class="p">,</span>
                        <span class="nx">escVal</span> <span class="o">=</span> <span class="p">(</span><span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span> <span class="o">?</span> <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\\/g</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
                        <span class="nx">test</span><span class="p">;</span>

                    <span class="c1">// add prefiltering for ID and CLASS</span>
                    <span class="k">if</span> <span class="p">((</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;id&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">operator</span> <span class="o">===</span> <span class="s1">&#39;=&#39;</span><span class="p">)</span> <span class="o">||</span>
                            <span class="p">(</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;className&#39;</span> <span class="o">&amp;&amp;</span>
                            <span class="nx">Y_DOCUMENT_ELEMENT</span><span class="p">.</span><span class="nx">getElementsByClassName</span> <span class="o">&amp;&amp;</span>
                            <span class="p">(</span><span class="nx">operator</span> <span class="o">===</span> <span class="s1">&#39;~=&#39;</span> <span class="o">||</span> <span class="nx">operator</span> <span class="o">===</span> <span class="s1">&#39;=&#39;</span><span class="p">)))</span> <span class="p">{</span>
                        <span class="nx">token</span><span class="p">.</span><span class="nx">prefilter</span> <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>


                        <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">escVal</span><span class="p">;</span> 

                        <span class="c1">// escape all but ID for prefilter, which may run through QSA (via Dom.allById)</span>
                        <span class="nx">token</span><span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;id&#39;</span><span class="p">)</span> <span class="o">?</span> <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">:</span> <span class="nx">escVal</span><span class="p">;</span>

                    <span class="p">}</span>

                    <span class="c1">// add tests</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">operator</span> <span class="k">in</span> <span class="nx">operators</span><span class="p">)</span> <span class="p">{</span>
                        <span class="nx">test</span> <span class="o">=</span> <span class="nx">operators</span><span class="p">[</span><span class="nx">operator</span><span class="p">];</span>
                        <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">test</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">escVal</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_reRegExpTokens</span><span class="p">,</span> <span class="s1">&#39;\\$1&#39;</span><span class="p">);</span>
                            <span class="nx">test</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">test</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;{val}&#39;</span><span class="p">,</span> <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">]));</span>
                        <span class="p">}</span>
                        <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">test</span><span class="p">;</span>
                    <span class="p">}</span>
                    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">token</span><span class="p">.</span><span class="nx">last</span> <span class="o">||</span> <span class="nx">token</span><span class="p">.</span><span class="nx">prefilter</span> <span class="o">!==</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="p">{</span>
                        <span class="k">return</span> <span class="nx">match</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
                    <span class="p">}</span>
                <span class="p">}</span>

            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">TAG_NAME</span><span class="p">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^((?:-?[_a-z]+[\w-]*)|\*)/i</span><span class="p">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">match</span><span class="p">,</span> <span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
                    <span class="kd">var</span> <span class="nx">tag</span> <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">toUpperCase</span><span class="p">();</span>
                    <span class="nx">token</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">=</span> <span class="nx">tag</span><span class="p">;</span>

                    <span class="k">if</span> <span class="p">(</span><span class="nx">tag</span> <span class="o">!==</span> <span class="s1">&#39;*&#39;</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="o">!</span><span class="nx">token</span><span class="p">.</span><span class="nx">last</span> <span class="o">||</span> <span class="nx">token</span><span class="p">.</span><span class="nx">prefilter</span><span class="p">))</span> <span class="p">{</span>
                        <span class="k">return</span> <span class="p">[</span><span class="nx">TAG_NAME</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="nx">tag</span><span class="p">];</span>
                    <span class="p">}</span>
                    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">token</span><span class="p">.</span><span class="nx">prefilter</span><span class="p">)</span> <span class="p">{</span>
                        <span class="nx">token</span><span class="p">.</span><span class="nx">prefilter</span> <span class="o">=</span> <span class="s1">&#39;tagName&#39;</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">COMBINATOR</span><span class="p">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^\s*([&gt;+~]|\s)\s*/</span><span class="p">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">match</span><span class="p">,</span> <span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
                <span class="p">}</span>
            <span class="p">},</span>
            <span class="p">{</span>
                <span class="nx">name</span><span class="o">:</span> <span class="nx">PSEUDOS</span><span class="p">,</span>
                <span class="nx">re</span><span class="o">:</span> <span class="sr">/^:([\-\w]+)(?:\uE005[&#39;&quot;]?([^\uE005]*)[&#39;&quot;]?\uE006)*/i</span><span class="p">,</span>
                <span class="nx">fn</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">match</span><span class="p">,</span> <span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
                    <span class="kd">var</span> <span class="nx">test</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">[</span><span class="nx">PSEUDOS</span><span class="p">][</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nx">test</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// reorder match array and unescape special chars for tests</span>
                        <span class="k">if</span> <span class="p">(</span><span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="p">{</span>
                            <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\\/g</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
                        <span class="p">}</span>
                        <span class="k">return</span> <span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="nx">test</span><span class="p">];</span> 
                    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// selector token not supported (possibly missing CSS3 module)</span>
                        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">}</span>
            <span class="p">],</span>

        <span class="nx">_getToken</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">token</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">return</span> <span class="p">{</span>
                <span class="nx">tagName</span><span class="o">:</span> <span class="kc">null</span><span class="p">,</span>
                <span class="nx">id</span><span class="o">:</span> <span class="kc">null</span><span class="p">,</span>
                <span class="nx">className</span><span class="o">:</span> <span class="kc">null</span><span class="p">,</span>
                <span class="nx">attributes</span><span class="o">:</span> <span class="p">{},</span>
                <span class="nx">combinator</span><span class="o">:</span> <span class="kc">null</span><span class="p">,</span>
                <span class="nx">tests</span><span class="o">:</span> <span class="p">[]</span>
            <span class="p">};</span>
        <span class="p">},</span>

        <span class="cm">/**</span>
<span class="cm">            Break selector into token units per simple selector.</span>
<span class="cm">            Combinator is attached to the previous token.</span>
<span class="cm">         */</span>
        <span class="nx">_tokenize</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">selector</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span> <span class="o">||</span> <span class="s1">&#39;&#39;</span><span class="p">;</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_replaceShorthand</span><span class="p">(</span><span class="nx">Y_Lang</span><span class="p">.</span><span class="nx">trim</span><span class="p">(</span><span class="nx">selector</span><span class="p">));</span> 
            <span class="kd">var</span> <span class="nx">token</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_getToken</span><span class="p">(),</span>     <span class="c1">// one token per simple selector (left selector holds combinator)</span>
                <span class="nx">query</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">,</span> <span class="c1">// original query for debug report</span>
                <span class="nx">tokens</span> <span class="o">=</span> <span class="p">[],</span>    <span class="c1">// array of tokens</span>
                <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span>  <span class="c1">// whether or not any matches were found this pass</span>
                <span class="nx">match</span><span class="p">,</span>         <span class="c1">// the regex match</span>
                <span class="nx">test</span><span class="p">,</span>
                <span class="nx">i</span><span class="p">,</span> <span class="nx">parser</span><span class="p">;</span>

            <span class="cm">/*</span>
<span class="cm">                Search for selector patterns, store, and strip them from the selector string</span>
<span class="cm">                until no patterns match (invalid selector) or we run out of chars.</span>

<span class="cm">                Multiple attributes and pseudos are allowed, in any order.</span>
<span class="cm">                for example:</span>
<span class="cm">                    &#39;form:first-child[type=button]:not(button)[lang|=en]&#39;</span>
<span class="cm">            */</span>

            <span class="nx">outer</span><span class="o">:</span>
            <span class="k">do</span> <span class="p">{</span>
                <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span> <span class="c1">// reset after full pass</span>

                <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="p">(</span><span class="nx">parser</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_parsers</span><span class="p">[</span><span class="nx">i</span><span class="o">++</span><span class="p">]);)</span> <span class="p">{</span>
                    <span class="k">if</span> <span class="p">(</span> <span class="p">(</span><span class="nx">match</span> <span class="o">=</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">re</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">selector</span><span class="p">))</span> <span class="p">)</span> <span class="p">{</span> <span class="c1">// note assignment</span>
                        <span class="k">if</span> <span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">name</span> <span class="o">!==</span> <span class="nx">COMBINATOR</span> <span class="p">)</span> <span class="p">{</span>
                            <span class="nx">token</span><span class="p">.</span><span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">;</span>
                        <span class="p">}</span>
                        <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">match</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;&#39;</span><span class="p">);</span> <span class="c1">// strip current match from selector</span>
                        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">selector</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">token</span><span class="p">.</span><span class="nx">last</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
                        <span class="p">}</span>

                        <span class="k">if</span> <span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_attrFilters</span><span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span> <span class="p">{</span> <span class="c1">// convert class to className, etc.</span>
                            <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_attrFilters</span><span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
                        <span class="p">}</span>

                        <span class="nx">test</span> <span class="o">=</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">fn</span><span class="p">(</span><span class="nx">match</span><span class="p">,</span> <span class="nx">token</span><span class="p">);</span>
                        <span class="k">if</span> <span class="p">(</span><span class="nx">test</span> <span class="o">===</span> <span class="kc">false</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// selector not supported</span>
                            <span class="nx">found</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
                            <span class="k">break</span> <span class="nx">outer</span><span class="p">;</span>
                        <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">test</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">token</span><span class="p">.</span><span class="nx">tests</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">test</span><span class="p">);</span>
                        <span class="p">}</span>

                        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">selector</span><span class="p">.</span><span class="nx">length</span> <span class="o">||</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">COMBINATOR</span><span class="p">)</span> <span class="p">{</span>
                            <span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">token</span><span class="p">);</span>
                            <span class="nx">token</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">_getToken</span><span class="p">(</span><span class="nx">token</span><span class="p">);</span>
                            <span class="k">if</span> <span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">COMBINATOR</span><span class="p">)</span> <span class="p">{</span>
                                <span class="nx">token</span><span class="p">.</span><span class="nx">combinator</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">combinators</span><span class="p">[</span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
                            <span class="p">}</span>
                        <span class="p">}</span>
                        <span class="nx">found</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>


                    <span class="p">}</span>
                <span class="p">}</span>
            <span class="p">}</span> <span class="k">while</span> <span class="p">(</span><span class="nx">found</span> <span class="o">&amp;&amp;</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span>

            <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">found</span> <span class="o">||</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// not fully parsed</span>
                <span class="nx">YAHOO</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;query: &#39;</span> <span class="o">+</span> <span class="nx">query</span> <span class="o">+</span> <span class="s1">&#39; contains unsupported token in: &#39;</span> <span class="o">+</span> <span class="nx">selector</span><span class="p">,</span> <span class="s1">&#39;warn&#39;</span><span class="p">,</span> <span class="s1">&#39;Selector&#39;</span><span class="p">);</span>
                <span class="nx">tokens</span> <span class="o">=</span> <span class="p">[];</span>
            <span class="p">}</span>
            <span class="k">return</span> <span class="nx">tokens</span><span class="p">;</span>
        <span class="p">},</span>

        <span class="nx">_replaceShorthand</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">selector</span><span class="p">)</span> <span class="p">{</span>
            <span class="kd">var</span> <span class="nx">shorthand</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">shorthand</span><span class="p">,</span>
                <span class="nx">esc</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">esc</span><span class="p">),</span> <span class="c1">// pull escaped colon, brackets, etc. </span>
                <span class="nx">attrs</span><span class="p">,</span>
                <span class="nx">pseudos</span><span class="p">,</span>
                <span class="nx">re</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">len</span><span class="p">;</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">esc</span><span class="p">)</span> <span class="p">{</span>
                <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">esc</span><span class="p">,</span> <span class="s1">&#39;\uE000&#39;</span><span class="p">);</span>
            <span class="p">}</span>

            <span class="nx">attrs</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">attr</span><span class="p">);</span>
            <span class="nx">pseudos</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">pseudos</span><span class="p">);</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">attrs</span><span class="p">)</span> <span class="p">{</span>
                <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">attr</span><span class="p">,</span> <span class="s1">&#39;\uE001&#39;</span><span class="p">);</span>
            <span class="p">}</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">pseudos</span><span class="p">)</span> <span class="p">{</span>
                <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">_re</span><span class="p">.</span><span class="nx">pseudos</span><span class="p">,</span> <span class="s1">&#39;\uE002&#39;</span><span class="p">);</span>
            <span class="p">}</span>


            <span class="k">for</span> <span class="p">(</span><span class="nx">re</span> <span class="k">in</span> <span class="nx">shorthand</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">if</span> <span class="p">(</span><span class="nx">shorthand</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">re</span><span class="p">))</span> <span class="p">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">re</span><span class="p">,</span> <span class="s1">&#39;gi&#39;</span><span class="p">),</span> <span class="nx">shorthand</span><span class="p">[</span><span class="nx">re</span><span class="p">]);</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">attrs</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">attrs</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\uE001/</span><span class="p">,</span> <span class="nx">attrs</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">pseudos</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">pseudos</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\uE002/</span><span class="p">,</span> <span class="nx">pseudos</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\[/g</span><span class="p">,</span> <span class="s1">&#39;\uE003&#39;</span><span class="p">);</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\]/g</span><span class="p">,</span> <span class="s1">&#39;\uE004&#39;</span><span class="p">);</span>

            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\(/g</span><span class="p">,</span> <span class="s1">&#39;\uE005&#39;</span><span class="p">);</span>
            <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\)/g</span><span class="p">,</span> <span class="s1">&#39;\uE006&#39;</span><span class="p">);</span>

            <span class="k">if</span> <span class="p">(</span><span class="nx">esc</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">esc</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
                    <span class="nx">selector</span> <span class="o">=</span> <span class="nx">selector</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;\uE000&#39;</span><span class="p">,</span> <span class="nx">esc</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
                <span class="p">}</span>
            <span class="p">}</span>

            <span class="k">return</span> <span class="nx">selector</span><span class="p">;</span>
        <span class="p">},</span>

        <span class="nx">_attrFilters</span><span class="o">:</span> <span class="p">{</span>
            <span class="s1">&#39;class&#39;</span><span class="o">:</span> <span class="s1">&#39;className&#39;</span><span class="p">,</span>
            <span class="s1">&#39;for&#39;</span><span class="o">:</span> <span class="s1">&#39;htmlFor&#39;</span>
        <span class="p">},</span>

        <span class="nx">getters</span><span class="o">:</span> <span class="p">{</span>
            <span class="nx">href</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">attr</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">return</span> <span class="nx">Y_DOM</span><span class="p">.</span><span class="nx">getAttribute</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">attr</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">};</span>

<span class="nx">Y_mix</span><span class="p">(</span><span class="nx">Selector</span><span class="p">,</span> <span class="nx">SelectorCSS2</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="nx">Selector</span><span class="p">.</span><span class="nx">getters</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">getters</span><span class="p">.</span><span class="nx">rel</span> <span class="o">=</span> <span class="nx">Selector</span><span class="p">.</span><span class="nx">getters</span><span class="p">.</span><span class="nx">href</span><span class="p">;</span>

<span class="c1">// IE wants class with native queries</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">Selector</span><span class="p">.</span><span class="nx">useNative</span> <span class="o">&amp;&amp;</span> <span class="nx">Y_DOC</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">Selector</span><span class="p">.</span><span class="nx">shorthand</span><span class="p">[</span><span class="s1">&#39;\\.([^\\s\\\\(\\[:]*)&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;[class~=$1]&#39;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>

                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class=""><a href="module_animation.html" title="animation">animation</a></li>
                                <li class=""><a href="module_autocomplete.html" title="autocomplete">autocomplete</a></li>
                                <li class=""><a href="module_button.html" title="button">button</a></li>
                                <li class=""><a href="module_calendar.html" title="calendar">calendar</a></li>
                                <li class=""><a href="module_carousel.html" title="carousel">carousel</a></li>
                                <li class=""><a href="module_charts.html" title="charts">charts</a></li>
                                <li class=""><a href="module_colorpicker.html" title="colorpicker">colorpicker</a></li>
                                <li class=""><a href="module_connection.html" title="connection">connection</a></li>
                                <li class=""><a href="module_container.html" title="container">container</a></li>
                                <li class=""><a href="module_cookie.html" title="cookie">cookie</a></li>
                                <li class=""><a href="module_datasource.html" title="datasource">datasource</a></li>
                                <li class=""><a href="module_datatable.html" title="datatable">datatable</a></li>
                                <li class=""><a href="module_datemath.html" title="datemath">datemath</a></li>
                                <li class=""><a href="module_dom.html" title="dom">dom</a></li>
                                <li class=""><a href="module_dragdrop.html" title="dragdrop">dragdrop</a></li>
                                <li class=""><a href="module_editor.html" title="editor">editor</a></li>
                                <li class=""><a href="module_element.html" title="element">element</a></li>
                                <li class=""><a href="module_element-delegate.html" title="element-delegate">element-delegate</a></li>
                                <li class=""><a href="module_event.html" title="event">event</a></li>
                                <li class=""><a href="module_event-delegate.html" title="event-delegate">event-delegate</a></li>
                                <li class=""><a href="module_event-mouseenter.html" title="event-mouseenter">event-mouseenter</a></li>
                                <li class=""><a href="module_event-simulate.html" title="event-simulate">event-simulate</a></li>
                                <li class=""><a href="module_get.html" title="get">get</a></li>
                                <li class=""><a href="module_history.html" title="history">history</a></li>
                                <li class=""><a href="module_imagecropper.html" title="imagecropper">imagecropper</a></li>
                                <li class=""><a href="module_imageloader.html" title="imageloader">imageloader</a></li>
                                <li class=""><a href="module_json.html" title="json">json</a></li>
                                <li class=""><a href="module_layout.html" title="layout">layout</a></li>
                                <li class=""><a href="module_logger.html" title="logger">logger</a></li>
                                <li class=""><a href="module_menu.html" title="menu">menu</a></li>
                                <li class=""><a href="module_paginator.html" title="paginator">paginator</a></li>
                                <li class=""><a href="module_profiler.html" title="profiler">profiler</a></li>
                                <li class=""><a href="module_profilerviewer.html" title="profilerviewer">profilerviewer</a></li>
                                <li class=""><a href="module_progressbar.html" title="progressbar">progressbar</a></li>
                                <li class=""><a href="module_resize.html" title="resize">resize</a></li>
                                <li class="selected"><a href="module_selector.html" title="selector">selector</a></li>
                                <li class=""><a href="module_slider.html" title="slider">slider</a></li>
                                <li class=""><a href="module_storage.html" title="Storage">Storage</a></li>
                                <li class=""><a href="module_stylesheet.html" title="stylesheet">stylesheet</a></li>
                                <li class=""><a href="module_swf.html" title="swf">swf</a></li>
                                <li class=""><a href="module_swfdetect.html" title="swfdetect">swfdetect</a></li>
                                <li class=""><a href="module_swfstore.html" title="swfstore">swfstore</a></li>
                                <li class=""><a href="module_tabview.html" title="tabview">tabview</a></li>
                                <li class=""><a href="module_treeview.html" title="treeview">treeview</a></li>
                                <li class=""><a href="module_uploader.html" title="uploader">uploader</a></li>
                                <li class=""><a href="module_yahoo.html" title="yahoo">yahoo</a></li>
                                <li class=""><a href="module_yuiloader.html" title="yuiloader">yuiloader</a></li>
                                <li class=""><a href="module_yuitest.html" title="yuitest">yuitest</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.util.Selector.html" title="YAHOO.util.Selector">YAHOO.util.Selector</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class="selected"><a href="selector-css2.js.html" title="selector-css2.js">selector-css2.js</a></li>
                                <li class=""><a href="Selector.js.html" title="Selector.js">Selector.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">

    var ALL_YUI_PROPS = [{"access": "", "host": "YAHOO.util.Selector", "name": "attrAliases", "url": "YAHOO.util.Selector.html#property_attrAliases", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "document", "url": "YAHOO.util.Selector.html#property_document", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "filter", "url": "YAHOO.util.Selector.html#method_filter", "type": "method"}, {"access": "", "host": "YAHOO.util.Selector", "name": "operators", "url": "YAHOO.util.Selector.html#property_operators", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "PARENT_NODE", "url": "YAHOO.util.Selector.html#property_PARENT_NODE", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "pseudos", "url": "YAHOO.util.Selector.html#property_pseudos", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "query", "url": "YAHOO.util.Selector.html#method_query", "type": "method"}, {"access": "", "host": "YAHOO.util.Selector", "name": "shorthand", "url": "YAHOO.util.Selector.html#property_shorthand", "type": "property"}, {"access": "", "host": "YAHOO.util.Selector", "name": "test", "url": "YAHOO.util.Selector.html#method_test", "type": "method"}, {"access": "", "host": "YAHOO.util.Selector", "name": "_tokenize", "url": "YAHOO.util.Selector.html#method__tokenize", "type": "method"}];
</script>
</body>
</html>
